﻿using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using DevExpress.Utils;
using DevExpress.XtraEditors;
using Dictionary.ERP;
using Common;
using System.Data;

namespace Dictionary
{
    public class xucSymbolList : xucBase
    {
        private readonly IContainer components = null;
        private FlowLayoutPanel flowLayoutPanel1;
        private FlowLayoutPanel flowLayoutPanel2;
        private bool m_IsShowLateEarly;
        private bool m_IsShowShift;
        private XtraScrollableControl xtraScrollableControl1;

        public xucSymbolList()
        {
            InitializeComponent();
        }

        private void bt_Click(object sender, EventArgs e)
        {
            var symbol = new xfmSymbol();
            symbol.Updated += (s, o) => Init(m_IsShowLateEarly, m_IsShowShift);
            symbol.Deleted += (s, o) => Init(m_IsShowLateEarly, m_IsShowShift);
            symbol.Added += (s, o) => Init(m_IsShowLateEarly, m_IsShowShift);
            symbol.ShowDialog();
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        public void Init(bool IsShowLateEarly, bool IsShowShift)
        {
            var dic_symbol = new DIC_SYMBOL();
            flowLayoutPanel1.Controls.Clear();
            flowLayoutPanel2.Controls.Clear();
            foreach (DataRow row in dic_symbol.GetList().Rows)
            {
                if (bool.Parse(row["IsShow"].ToString()))
                {
                    string str = "";
                    if (row["SymbolCode"].ToString() == "")
                    {
                        str = "(trống)";
                    }
                    else if (((row["SymbolCode"].ToString() == "CS") || (row["SymbolCode"].ToString() == "KCR")) ||
                             (row["SymbolCode"].ToString() == "KCV"))
                    {
                        str = "<color=red>" + row["SymbolCode"].ToString() + "</color>";
                    }
                    else
                    {
                        str = row["SymbolCode"].ToString();
                    }
                    var item = new xucSymbolItem
                    {
                        Height = 13,
                        SymbolCode = ":  " + str,
                        SymbolName = row["SymbolName"].ToString()
                    };
                    flowLayoutPanel1.Controls.Add(item);
                }
            }
            if (m_IsShowLateEarly = IsShowLateEarly)
            {
                var item2 = new xucSymbolItem
                {
                    Height = 13,
                    SymbolCode = ":  +(số ph\x00fat)",
                    SymbolName = "Số ph\x00fat đi trễ"
                };
                flowLayoutPanel1.Controls.Add(item2);
                var item3 = new xucSymbolItem
                {
                    Height = 13,
                    SymbolCode = ":  -(số ph\x00fat)",
                    SymbolName = "Số ph\x00fat về sớm"
                };
                flowLayoutPanel1.Controls.Add(item3);
                var item4 = new xucSymbolItem
                {
                    Height = 13,
                    SymbolCode = ": +(sp):-(sp)",
                    SymbolName = "Đi trễ, về sớm"
                };
                flowLayoutPanel1.Controls.Add(item4);
                var item5 = new xucSymbolItem
                {
                    Height = 13,
                    SymbolCode = ": <color=black>+;V +;P ...</color>",
                    SymbolName = "<color=black>T\x00e1ch đ\x00f4i ca</color>"
                };
                flowLayoutPanel1.Controls.Add(item5);
            }
            if (m_IsShowShift = IsShowShift)
            {
                flowLayoutPanel2.Height = 0x11;
                var dic_shift = new DIC_SHIFT();
                var control = new LabelControl
                {
                    Text = "* K\x00fd hiệu theo ca: "
                };
                flowLayoutPanel2.Controls.Add(control);
                foreach (DataRow row2 in dic_shift.GetList().Rows)
                {
                    var item6 = new xucSymbolItem
                    {
                        Height = 13,
                        Width = 0xb8
                    };
                    item6.lbSymbolCode.Width = 0x2e;
                    item6.SymbolCode = ":  <color=blue>" + row2["ShiftCode"].ToString() + "</color>";
                    item6.SymbolName = "<u>" + row2["ShiftName"].ToString() + " <i>(" +
                                       Convert.ToDateTime(row2["BeginTime"]).ToShortTimeString() + " - " +
                                       Convert.ToDateTime(row2["EndTime"]).ToShortTimeString() + ")</i></u>";
                    var tip = new SuperToolTip();
                    tip.Items.AddTitle(row2["ShiftName"].ToString() + " (" +
                                       Convert.ToDateTime(row2["BeginTime"]).ToShortTimeString() + " - " +
                                       Convert.ToDateTime(row2["EndTime"]).ToShortTimeString() + "): " +
                                       row2["ShiftCode"].ToString());
                    if (Convert.ToBoolean(row2["IsOvernight"].ToString()))
                    {
                        tip.Items.Add("- L\x00e0m việc qua đ\x00eam");
                    }
                    if (Convert.ToBoolean(row2["IsBreak"].ToString()))
                    {
                        tip.Items.Add("- Nghỉ giữa ca từ " +
                                      Convert.ToDateTime(row2["BreakBeginTime"]).ToShortTimeString() + " - " +
                                      Convert.ToDateTime(row2["BreakEndTime"]).ToShortTimeString());
                    }
                    else
                    {
                        tip.Items.Add("- Kh\x00f4ng nghỉ giữa ca");
                    }
                    item6.lbSymbolName.SuperTip = tip;
                    flowLayoutPanel2.Controls.Add(item6);
                }
            }
            else
            {
                flowLayoutPanel2.Height = 0;
            }
            var button = new SimpleButton
            {
                Text = "Chỉnh Sửa Bảng K\x00fd Hiệu Chấm C\x00f4ng",
                Width = 200
            };
            button.Click += bt_Click;
            flowLayoutPanel1.Controls.Add(button);
        }

        private void InitializeComponent()
        {
            flowLayoutPanel1 = new FlowLayoutPanel();
            xtraScrollableControl1 = new XtraScrollableControl();
            flowLayoutPanel2 = new FlowLayoutPanel();
            xtraScrollableControl1.SuspendLayout();
            base.SuspendLayout();
            flowLayoutPanel1.AutoSize = true;
            flowLayoutPanel1.AutoSizeMode = AutoSizeMode.GrowAndShrink;
            flowLayoutPanel1.Dock = DockStyle.Left;
            flowLayoutPanel1.FlowDirection = FlowDirection.TopDown;
            flowLayoutPanel1.Location = new Point(0, 0);
            flowLayoutPanel1.Margin = new Padding(120);
            flowLayoutPanel1.Name = "flowLayoutPanel1";
            flowLayoutPanel1.Padding = new Padding(10, 0, 0, 0);
            flowLayoutPanel1.Size = new Size(10, 250);
            flowLayoutPanel1.TabIndex = 0;
            xtraScrollableControl1.Controls.Add(flowLayoutPanel1);
            xtraScrollableControl1.Controls.Add(flowLayoutPanel2);
            xtraScrollableControl1.Dock = DockStyle.Fill;
            xtraScrollableControl1.Location = new Point(0, 0);
            xtraScrollableControl1.Name = "xtraScrollableControl1";
            xtraScrollableControl1.Size = new Size(0x2b9, 250);
            xtraScrollableControl1.TabIndex = 1;
            flowLayoutPanel2.AutoSize = true;
            flowLayoutPanel2.AutoSizeMode = AutoSizeMode.GrowAndShrink;
            flowLayoutPanel2.Dock = DockStyle.Bottom;
            flowLayoutPanel2.Location = new Point(0, 250);
            flowLayoutPanel2.Margin = new Padding(120);
            flowLayoutPanel2.Name = "flowLayoutPanel2";
            flowLayoutPanel2.Padding = new Padding(10, 0, 0, 0);
            flowLayoutPanel2.Size = new Size(0x2b9, 0);
            flowLayoutPanel2.TabIndex = 1;
            base.AutoScaleDimensions = new SizeF(6f, 13f);
            base.AutoScaleMode = AutoScaleMode.Font;
            base.Controls.Add(xtraScrollableControl1);
            base.Name = "xucSymbolList";
            base.Size = new Size(0x2b9, 250);
            xtraScrollableControl1.ResumeLayout(false);
            xtraScrollableControl1.PerformLayout();
            base.ResumeLayout(false);
        }
    }
}